// TestConncetionLibraryClient.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include "Libs/Native/Common/FastLogger.h"
#include "Libs/Native/ConnectionLibrary/ConnectionLibrary.h"

#include "ClientNotificationHandler.h"
#include <iostream>
#include <sstream>

#include "Libs/Native/Messages/Message.P2.AddOrder.h"
#include "Libs/Native/Messages/Message.P2.GetQuotes.h"

using namespace AlgoTrading::ConnectionLibrary;

int _tmain(int argc, _TCHAR* argv[])
{
	AlgoTrading::Logging::fastLogger.Start();


	std::auto_ptr<ClientConnectionLibrary> clientConnectionLibrary = CreateClientConnectionLibraryInstance();

	clientConnectionLibrary->Start();

	std::tr1::shared_ptr<NotificationHandler> ptr(new ClientNotificationHandler());
	std::auto_ptr<FeedConnector> feed = clientConnectionLibrary->CreateFeedConnector(ptr);
	boost::system::error_code error = feed->Connect(std::string("localhost"), std::string("9999"));
	if (!error)
	{
		for(int i = 0; i < 10000; ++i)
		{
			AlgoTrading::Messages::P2GetQuotes getQuotes;
			getQuotes.SetRequestId(1);
			getQuotes.SetSequrityId(20);
			feed->SendRequest(getQuotes);

			//AlgoTrading::Messages::P2AddOrder order;
			//order.SetOrderUniqueId(::google::protobuf::string("test"));
			//order.SetOrderType(AlgoTrading::Messages::P2AddOrder::ORDER_TYPE_ASK);
			//order.SetOrderAmount(10);
			//order.SetOrderPrice(10.0);
			//order.SetSequrity(::google::protobuf::string("testSecurity"));
			//feed->SendRequest(order);
		}
	}
	else
	{
		std::cout << error.message();
	}

	int i = 0;
	std::cin >> i;

	feed->Disconnect();
	

	clientConnectionLibrary->Stop();

	return 0;
}

